$(function () {

    function chaxun(pagenum){

        $.post("news/newsfenye",{"pagenum":pagenum},function (data) {
            $(".m_right").empty();
            $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px">咨询列表</h1>\n' +
                '            <table border="1px" width="80%" style="font-size: 16px;margin-top: 30px" id="xianshi">\n' +
                '            </table>\n' +
                '            <div id="yeshu" class="pages">\n' +
                '                <span style="border-color: #333333;border : 1px solid #000000;border-width: 2px;display:inline-block;width: 40px;height:50px;text-align: center;margin-top: 50px;margin-left: 30px">\n' +
                '                    <a href="" style="font-size: 25px;margin-top: 10px;display: inline-block">1</a>\n' +
                '                </span>\n' +
                '            </div>'));
            $("#xianshi").empty();
            $("#yeshu").empty();
            $("#xianshi").append($('<tr style="font-size: 20px">\n' +
                '                    <th>标题</th>\n' +
                '                    <th>创建时间</th>\n' +
                '                </tr>'));

            $.each(data.list,function (index,news) {
                var c = escape(news.content);
                var t = escape(news.title);

                var reg = RegExp(/特惠/);

                if(reg.test(news.title)){
                    $("#xianshi").append($('<tr>\n' +
                        '                        <td><a href="javascript:;" class="nr" data-title="'+news.title+'" data-content="'+news.content+'" data-num="'+data.pageNum+'"><span style="color: deepskyblue">[ 特惠 ]</span>\n' +
                        '                            <span style="margin-left: 30px">' + news.title + '</span></a>\n' +
                        '                        </td>\n' +
                        '                        <td>'+news.createtime+'</td>\n' +
                        '                    </tr>'))
                }else {
                    $("#xianshi").append($('<tr>\n' +
                        '                        <td><a href="javascript:;" class="nr" data-title="'+news.title+'" data-content="'+news.content+'" data-num="'+data.pageNum+'"><span style="color: deepskyblue">[ 公告 ]</span>\n' +
                        '                            <span style="margin-left: 30px">' + news.title + '</span></a>\n' +
                        '                        </td>\n' +
                        '                        <td>'+news.createtime+'</td>\n' +
                        '                    </tr>'))
                }
            });

            if(data.hasPreviousPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="1">首页</a>\n' +
                    '                </span>')
            }
            $.each(data.navigatepageNums,function (i,a) {
                if(a==data.pageNum){
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" style="background-color: pink" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }else {
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }
            });
            if(data.hasNextPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="'+data.pages+'">末页</a>\n' +
                    '                </span>')
            }

            $(".m_right").append($('<div style="margin-left: 850px;margin-top: 10px"><a href="index.html" style="border: black solid 2px;font-size: 20px;background-color: #91b817">主页面</a></div>'))


            $(".yeshu").click(function () {
                var a = $(this).data("id");
                chaxun(a);
            })
        })

    }


    function xiangqing(title,content,num) {
        $(".m_right").empty();
        $(".m_right").append($('<div class="neirong"></div>\n' +
            '            <div style="margin-left: 700px;margin-top: 100px">\n' +
            '            <a href="index.html" style="border: black solid 2px;font-size: 20px;background-color: #91b817">主页面</a>\n' +
            '            <a href="javascript:;" style="border: black solid 2px;font-size: 20px;background-color: #91b817" class="zxlb" data-num="'+num+'">咨询列表页面</a>\n' +
            '            </div>'));

        $(".neirong").append($('<h1 style="margin-top: 50px;margin-left: 50px;color: pink">'+title+'</h1>' +
            '<h2 style="margin-top: 50px;margin-left: 100px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+content+'</h2>'));

        $(".zxlb").click(function () {
            var num = $(this).data("num");
            chaxun(num);
        })

    }


    if(localStorage.num==1){
        chaxun(1);
    }else {
        var title = localStorage.title;
        var content = localStorage.content;
        xiangqing(title,content,1)
    }

    $(".m_right").on("click",".nr",function () {
        var title = $(this).data("title");
        var content = $(this).data("content");
        var num = $(this).data("num");
        xiangqing(title,content,num);
    })



})